package com.bbms.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

/**
 * 图书信息实体
 */
@Entity
@Table(name = "bbms_book")
public class Book implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private int id;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "author")
	private String author;
	
	@Column(name = "publisher_id")
	private int publisherId;
	@Column(name = "publish_date")
	private Date publishDate;
	
	@Column(name = "category_id")
	private int categoryId;
	
	@Column(name = "price")
	private double price;
	
	@Column(name = "ISBN")
	private String ISBN;
	
	@Column(name = "status")
	private int status;
	
	@Column(name = "book_register_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date bookRegisterTime;
	
	@Column(name = "book_logout_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date bookLogoutTime;

	public Book() {
		super();
	}

	public Book(int id, String name, String author, int publisherId, Date publishDate, int categoryId, double price,
			String ISBN, int status, Date bookRegisterTime, Date bookLogoutTime) {
		super();
		this.id = id;
		this.name = name;
		this.author = author;
		this.publisherId = publisherId;
		this.publishDate = publishDate;
		this.categoryId = categoryId;
		this.price = price;
		this.ISBN = ISBN;
		this.status = status;
		this.bookRegisterTime = bookRegisterTime;
		this.bookLogoutTime = bookLogoutTime;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public int getPublisherId() {
		return publisherId;
	}

	public void setPublisherId(int publisherId) {
		this.publisherId = publisherId;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getISBN() {
		return ISBN;
	}

	public void setISBN(String ISBN) {
		this.ISBN = ISBN;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getBookRegisterTime() {
		return bookRegisterTime;
	}

	public void setBookRegisterTime(Date bookRegisterTime) {
		this.bookRegisterTime = bookRegisterTime;
	}

	public Date getBookLogoutTime() {
		return bookLogoutTime;
	}

	public void setBookLogoutTime(Date bookLogoutTime) {
		this.bookLogoutTime = bookLogoutTime;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ISBN == null) ? 0 : ISBN.hashCode());
		result = prime * result + ((author == null) ? 0 : author.hashCode());
		result = prime * result + ((bookLogoutTime == null) ? 0 : bookLogoutTime.hashCode());
		result = prime * result + ((bookRegisterTime == null) ? 0 : bookRegisterTime.hashCode());
		result = prime * result + categoryId;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		long temp;
		temp = Double.doubleToLongBits(price);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((publishDate == null) ? 0 : publishDate.hashCode());
		result = prime * result + publisherId;
		result = prime * result + status;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (ISBN == null) {
			if (other.ISBN != null)
				return false;
		} else if (!ISBN.equals(other.ISBN))
			return false;
		if (author == null) {
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		if (bookLogoutTime == null) {
			if (other.bookLogoutTime != null)
				return false;
		} else if (!bookLogoutTime.equals(other.bookLogoutTime))
			return false;
		if (bookRegisterTime == null) {
			if (other.bookRegisterTime != null)
				return false;
		} else if (!bookRegisterTime.equals(other.bookRegisterTime))
			return false;
		if (categoryId != other.categoryId)
			return false;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price))
			return false;
		if (publishDate == null) {
			if (other.publishDate != null)
				return false;
		} else if (!publishDate.equals(other.publishDate))
			return false;
		if (publisherId != other.publisherId)
			return false;
		if (status != other.status)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Book [id=" + id + ", name=" + name + ", author=" + author + ", publisherId=" + publisherId
				+ ", publishDate=" + publishDate + ", categoryId=" + categoryId + ", price=" + price + ", ISBN=" + ISBN
				+ ", status=" + status + ", bookRegisterTime=" + bookRegisterTime + ", bookLogoutTime=" + bookLogoutTime
				+ "]";
	}
	
}
